<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="file" id="fileInput" placeholder="上传头像" accept="" style="display: none" />
    <button id="upload">上传文件</button>
    <div id="result">请上传头像</div>
    <script>
        upload.onclick = () => {
            fileInput.click();
        };
        fileInput.onchange = (e) => {
            const file = e.target.files[0];
            const formData = new FormData();
            formData.append("avatar", file);
            e.target.value = null;
            fetch("http://192.168.22.24:4000/file", {
                method: "POST",
                body: formData,
            })
                .then((res) => res.text())
                .then((res) => {
                    console.log(res)
                });
        };
    </script>
</body>

</html>